/*
 * Copyright 2012 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.dspl.validate.violation;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.dspl.model.DataType;
import com.google.dspl.model.Identifier;
import com.google.dspl.validate.ItemReference;

import java.util.List;

/**
 * Violation for a concept property whose type doesn't match the type of its concept.
 *
 * @author Maryla Ustarroz Calonge
 */
public final class ConceptPropertyConflictingConceptTypeViolation extends Violation {

  private static final long serialVersionUID = -2287913338082304527L;

  private final String propertyId;
  private final String enclosingConceptId;
  private final DataType propertyType;
  private final Identifier propertyConceptId;
  private final DataType propertyConceptType;

  public ConceptPropertyConflictingConceptTypeViolation(
      ItemReference location,
      String propertyId,
      String enclosingConceptId,
      DataType propertyType,
      Identifier propertyConceptId,
      DataType conceptType) {
    super(Severity.ERROR, location);
    this.propertyId = propertyId;
    this.enclosingConceptId = enclosingConceptId;
    this.propertyType = Preconditions.checkNotNull(propertyType);
    this.propertyConceptId = Preconditions.checkNotNull(propertyConceptId);
    this.propertyConceptType = Preconditions.checkNotNull(conceptType);
  }

  @Override
  public String getDefaultTemplate() {
    return
        "Property %s of concept %s has type %s which doesn't match the type %s of its concept %s";
  }

  @Override
  public List<Object> getDefaultTemplateParameters() {
    return ImmutableList.<Object>of(
        propertyId, enclosingConceptId, propertyType, propertyConceptType, propertyConceptId);
  }

  public String getPropertyId() {
    return propertyId;
  }

  public String getConceptId() {
    return enclosingConceptId;
  }

  public DataType getPropertyType() {
    return propertyType;
  }

  public Identifier getPropertyConceptId() {
    return propertyConceptId;
  }

  public DataType getPropertyConceptType() {
    return propertyConceptType;
  }

  @Override
  public <T> T accept(ViolationVisitor<T> visitor) {
    return visitor.visit(this);
  }
}
